package com.lmh.backend.service.serviceImpl;

import com.lmh.backend.dao.AuthorDao;
import com.lmh.backend.entity.Author;
import com.lmh.backend.entity.News;
import com.lmh.backend.service.AuthorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.Set;

@Service
public class AuthorServiceImpl implements AuthorService {
    private AuthorDao authorDao;

    @Autowired
    public void setAuthorDao(AuthorDao authorDao) {
        this.authorDao = authorDao;
    }

    @Override
    public Author getAuthorByName(String authorName) {
        return authorDao.getAuthorByName(authorName);
    }

    @Override
    public Set<News> getNewsFromAuthor(String authorName) {
        Author author = authorDao.getAuthorByName(authorName);
        return author.getNewsSet();
    }

    @Override
    public void save(Author author) {
        authorDao.save(author);
    }
}
